/*
 * WebCallBack.java
 *
 * Created on 4 Ноябрь 2006 г., 16:14
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package server.authentification.module;

import javax.servlet.ServletRequest;
import javax.security.auth.callback.*;

public class WebCallBack implements CallbackHandler{

    private String userName;
    private String password;
    public WebCallBack(ServletRequest request) {
        this.userName= request.getParameter("username");
        this.password=request.getParameter("password");
    }

    public void handle(Callback[] callbacks) throws java.io.IOException,
            UnsupportedCallbackException{

        for (int i = 0;i<callbacks.length;i++){
            if (callbacks[i] instanceof NameCallback){
                NameCallback namec = (NameCallback)callbacks[i];
                namec.setName(userName);
            }else if (callbacks[i] instanceof PasswordCallback){
                PasswordCallback passc = (PasswordCallback)callbacks[i];
                passc.setPassword(password.toCharArray());
            }else{
                throw new UnsupportedCallbackException(callbacks[i],"Callback "+getClass().getName());
            }

        }
    }
}